package com.example.thegreatwall.utils;

import com.example.thegreatwall.common.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 罗力
 * @version 1.0
 * @Description TODO 阿里云身份验证接口
 * @date 2024/10/4 22:34
 */
public class VerifyIdCard {
    static String testIdCard="***";//要检查的身份证号码
    static String name="***";  //要检查的对应身份证的姓名
    static String msg=null;//返回的信息
//    {

    public static void setTestIdCard(String testIdCard) {
        VerifyIdCard.testIdCard = testIdCard;
    }

    public static void setName(String name) {
        VerifyIdCard.name = name;
    }

    public static String getMsg() {
        return msg;
    }
//        "msg": "成功",
//            "success": true,
//            "code": 200,
//            "data": {
//        "birthday": "19920626",
//                "result": 0,
//                "address": "湖南省张家界市慈利县",
//                "orderNo": "20241005110058",
//                "sex": "女",
//                "desc": "一致"
//    }

    //    {
//        "msg": "成功",
//            "success": true,
//            "code": 200,
//            "data": {
//        "birthday": "19920626",
//                "result": 0,
//                "address": "湖南省张家界市慈利县",
//                "orderNo": "20241005110058",
//                "sex": "女",
//                "desc": "不一致"
//    }

//    {
//        "msg": "请输入有效的身份证号码",
//            "success": false,
//            "code": 400,
//            "data": null
//    }

    public static void main(String[] args) {
        //https://kzidcardv1.market.alicloudapi.com/api-mall/api/id_card/check
        String host = "https://kzidcardv1.market.alicloudapi.com";
        String path = "/api-mall/api/id_card/check";
        String method = "POST";
        String appcode = "31ae40269e084f90a04d5b70ee755e44";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        //bodys.put("name", "name");
        //bodys.put("idcard", "idCard");
        bodys.put("name", name);
        bodys.put("idcard", testIdCard);


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            //String result = HttpUtils.post(url, accessToken, "application/json", param);
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            //System.out.println(response);
            //System.out.println("aaaa");
            //获取response的body
            msg =EntityUtils.toString(response.getEntity());
            System.out.println(msg);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
